# 栈_先进后出,常用于深搜
import heapq
from collections import deque, defaultdict


def  use_stack():
    stack = []
    stack.append(1)
    stack.append(2)
    stack.append(3)
    top_element = stack.pop()
    print(top_element)
#deque
def  use_stack1():
    stack = deque()
    stack.append(1)
    stack.append(2)
    top_element = stack.pop()
    print(top_element)

# 队列
def use_deque():
    queue = deque()
    queue.append(1)
    queue.append(2)
    front_element = queue.popleft()
    #Returns a new deque object initialized left-to-right
    print(front_element)

# 树

def use_tree():
    class TreeNode:
        def __init__(self, val):
            self.val = val
            self.left = None
            self.right = None

    root = TreeNode(1)
    root.left = TreeNode(2)
    root.right = TreeNode(3)
    if root:
        print(root.val,root.left.val,root.right.val)

# 图

def use_graph():
    graph = defaultdict(list)
    graph[1].append(2)
    graph[1].append(3)
    graph[2].append(4)

    def dfs(graph, node, visited):
        if node not in visited:
            print(node)
            visited.add(node)
            for nieghbor in graph[node]:
                dfs(graph, nieghbor, visited)
    visited = set()
    dfs(graph, 1, visited)

# 堆
def use_heap():
    heap = []
    heapq.heappush(heap,3)
    heapq.heappush(heap,1)
    heapq.heappush(heap,2)
    min_element = heapq.heappop(heap)

#哈希表_快速查找、插入和删除数据

def use_hash_table():
    hash_table = {}
    hash_table['key1'] = 'value1'
    hash_table['key2'] = 'value2'
    value = hash_table.get('key1')

if __name__ == '__main__':
    use_graph()

